***********************************************************************
*
*	Lee-Liou 
*   Where You Work Is Where You Stand: 
*   A Firm-Based Framework for Understanding Trade Opinion
*	Data Prep Code
*	First Written 1/20/2015
*	Last Modified 1/19/2022
*
***********************************************************************

*Basefile contains all relevant variables from JGSS*
use "Basefile.dta", clear

***********************************************************************
*	Housekeeping Variables
***********************************************************************

*	ID
rename CASEID id

*	Survey weights
rename WEIGHT weight

*	Survey Form
rename FORM form

***********************************************************************
*	Geography
***********************************************************************

*	Region
rename BLOCK region

*	Prefecture
rename PREF prefecture

*	City Size
rename SIZE city_size

*	Area of residence
rename AREA res_area
	recode res_area (9=.)

***********************************************************************
*	Demographics
***********************************************************************

*	Female
rename SEXA female
	recode female (1=0) (2=1)
	label var female "Is R Female"
	label define ny 0 "No" 1 "Yes"
	label values female ny
	
*	Age
rename AGEB age
	recode age (2=1) (3=2) (4=3) (5=4) (6=5) (7=6) (8=7)
	label var age "Age"
	label define age 1 "20-29 years" 2 "30-39 years" 3 "40-49 years" ///
	4 "50-59 years" 5 "60-69 years" 6 "70-79 years" 7 "80-89 years"
	label values age age
	
*	Employment (Last Week)
rename XJOB1WK employed
	recode employed (1/2=1) (3=0)
	label var employed "Employed?"
	label values employed ny
	
*rename TPJOB job_type
	gen job_type = TPJOB
	recode job_type (7/8=.)

*	Consolidated job type	
recode job_type (1=1) (2=2) (3/4=3) (5/6=4), gen(job_type_con)
	label var job_type "Consolidated Job Type"
	label define job_type 1 "Executive" 2 "Regular Employee" ///
	3 "Temporary Worker" 4 "Self-Employed or Family Worker"
	label values job_type_con job_type
	
recode job_type (1/2=0) (3/4=1) (5/6=0), gen(temp_worker)
	label var temp_worker "Is R a Temp worker?"
	label values temp_worker ny
	
*	Management responsibility
recode TPJOBP (6/9=.), gen(mgmt_resp)
	replace mgmt_resp = 6 if job_type==1
	replace mgmt_resp = 1 if job_type==3 | job_type==4
	label var mgmt_resp "Level of management responsibility"
	label define mgmt_resp 1 "No managerial post" 2 "Group leader, Foreman" ///
	3 "Sub-section head" 4 "Section Head, Manager" 5 "Department Head, General Manager" ///
	6 "Executive"
	label values mgmt_resp mgmt_resp
	
*	mgmt_dum (TPJOB ==1 Executive, TPJOB == 5 Self-employed) 
recode mgmt_resp (6=1) (5=1) (4=0) (3=0) (2=0) (1=0), gen(mgmt_dum)
replace mgmt_dum = 1 if TPJOB ==1 | TPJOB == 5 

	
*	job satisfaction
*rename ST5JOB job_satisfaction
	gen job_satisfaction = ST5JOB
	recode job_satisfaction (6/9=.) (1=5) (2=4) (3=3) (4=2) (5=1)
	label var job_satisfaction "How satisfied are you with your job?"
	label define satisfaction 1 "Dissatisfied" 2 "Somewhat dissatisfied" ///
	3 "Neither satisfied nor dissatisfied" 4 "Somewhat satisfied" 5 "Satisfied"
	label values job_satisfaction satisfaction
	
*	Type of Workplace
*rename TP4WPLA	workplace_type
	gen workplace_type = TP4WPLA
	recode workplace_type (5/9=.)
	label var workplace_type "Workplace type"
	label define workplace_type 1 "Government agency" 2 "Independent establishment" ///
	3 "Branch establishment" 4 "Headquarters or main establishment"
	label values workplace_type workplace_type
	recode workplace_type (5/9=.)
		
*	Headquarters
recode workplace_type (1=.) (2=1) (3=0) (4=1), gen(hq)
	label var hq "Employed at headquarters of employer"
	label values hq ny
	
*	Industry
rename XXWPL industry
	recode industry (998/999=.)
	
*	Manufacturing dummy
recode industry (60=1) (10/50=0) (70/190=0), gen(manufacturing)
	label var manufacturing "Does R work in manufacturing?"
	label values manufacturing ny
	
*	Occupation
rename XXJOB occupation
	recode occupation (998/999=.)
	
*	ISCO-88 occupation
rename XXJOBE isco88
	recode isco88 (88888/99999=.)

*	primary dummy
recode industry (10/40=1) (50/190=0), gen(primary)
	label values primary ny
	
*	Create comparative advantage manufacturing dummy
gen manu_adv = 0
	label var manu_adv "Does R work in Comparative advantage manufacturing?"
	replace manu_adv = 1 if occupation==627 | occupation==628 | occupation==630 ///
		| occupation==631 | occupation==633 | occupation==633 | occupation==634 ///
		| occupation==635 | occupation==636
	replace manu_adv = 0 if manufacturing==0
	replace manu_adv = . if manufacturing==.
	
gen manu_disadv = 0
	replace manu_disadv = 1 if manufacturing==1 & manu_adv==0
	replace manu_disadv = . if manufacturing==.
	label var manu_adv "Does R work in Comparative disadvantage manufacturing?"
	label values manu_disadv ny
	
*	Primary Sectors + Comparative disadvantage manufacturing
gen comp_disadv = .
	replace comp_disadv = 1 if primary==1 | manu_disadv==1
	replace comp_disadv = 0 if primary==0 & manu_disadv==0
	label var comp_disadv "Does R work in Comparative Disadvantage Sector?"
	label values comp_disadv ny
		
*	Union
*rename JOINUNI union
	gen union = JOINUNI
	recode union (1/2=1) (3/4=0) (8/9=.)
	label var union "Union Member?"
	label values union ny
		
***********************************************************************
*	Skill Level
***********************************************************************

rename DOLSTSCH graduate
	recode graduate (1=1) (2/3=0) (9=.)
	label values graduate ny

*	Educational Attainment (graduates only)
rename XXLSTSCH ed_attain
	recode ed_attain (14/99=.) 
	replace ed_attain=. if graduate==0 | graduate==.
	
recode ed_attain (1/6=0) (7=1) (8/11=0) (12/13=1), gen(collgrad)
	label var collgrad "Is R a college/university graduate?"
	label values collgrad ny
	
recode ed_attain (1/6=0) (7=1) (8/9=0) (10=1) (11=0) (12/13=1), gen(collgrad_alt)
	label var collgrad_alt "Including CoT in college graduates"
	
***********************************************************************
*	Early Academic Success
***********************************************************************

rename OP5SCHPF early_achiever
	recode early_achiever (9=.)
	
***********************************************************************	
*	Employer Characteristics
***********************************************************************	

*	Size of Employer
rename SZTTLSTA emp_size
	recode emp_size (88/99=.) (12/13=.)
	label var emp_size "How many people work at employer?"

*   Recoding Size of Employer 
recode emp_size (1/8=0) (9/11=1), gen(empsize)

*	kernel density suggests break at 6/7
recode emp_size (1/6=0) (7/11=1), gen(emp_large)
	label var emp_large "Does employer have >299 employees?"
	label values emp_large ny
	
*	Employer imports goods
rename INTDIMP emp_import
	recode emp_import (0=0) (1=1) (8/9=.)
	label var emp_import "Does employer import goods?"
	label values emp_import ny
	
*	Employer exports goods
rename INTDEXP emp_export
	recode emp_export (1=1) (0=0) (8/9=.)
	label var emp_export "Does employer export goods?"
	label values emp_export ny
	
*	Employer imports and exports goods
gen emp_imp_exp = .
	replace emp_imp_exp = 0 if emp_import==0 | emp_export==0
	replace emp_imp_exp = 1 if emp_import==1 & emp_export==1
	label var emp_imp_exp "Does employer both import and export goods?"
	label values emp_imp_exp ny
	
*	Employer produces goods abroad
rename INTDPRD emp_offshore
	recode emp_offshore (1=1) (0=0) (8/9=.)
	label var emp_offshore "Does employer produce goods overseas?"
	label values emp_offshore ny
	
*	Employer not globalized
rename INTDNEX emp_dom
	recode emp_dom (1=1) (0=0) (8/9=.)
	label var emp_dom "Employer not part of global supply chain"
	label values emp_dom ny
	
*	Employer part of global supply chain
recode emp_dom (1=0) (0=1), gen(emp_glob)
	label var emp_glob "Employer is part of global supply chain"
	label values emp_glob ny
	
*	Employer is foreign capital company
rename JOBFCAP MNC
	recode MNC (1=1) (2/3=0) (8/9=.)
	label var MNC "Does R work for foreign capital company?"
	label values MNC ny
	
*	ordinal scale:
gen emp_glob_ord = .
	*	no globalized economic activity
	replace emp_glob_ord = 0 if emp_glob==0 & MNC==0
	*	import only
	replace emp_glob_ord = 1 if emp_import==1 & emp_export==0 & emp_offshore==0 & MNC!=1
	*	export but no FDI
	replace emp_glob_ord = 1 if emp_export==1 & emp_offshore==0 & MNC!=1
	*	FDI
	replace emp_glob_ord = 2 if emp_offshore==1 | MNC==1
	
* recoding emp_glob to include MNCs
	replace emp_glob = 1 if MNC==1
	
***********************************************************************
*	Personal Economic Insecurity
***********************************************************************
	
*	Probability of Losing Current Job
*rename OP4UNEMP jobloss_prob
gen jobloss_prob = OP4UNEMP
	recode jobloss_prob (1=4) (2=3) (3=2) (4=1) (5/9=.)
	label var jobloss_prob "Probability of losing job in next 12 months"
	label define likely 1 "Not at all likely" 2 "Not too likely" ///
	3 "Fairly likely" 4 "Very likely"
	label values jobloss_prob likely
		
***********************************************************************
*	Partisanship
***********************************************************************
	
*	PID
*rename XX8PLPTY pid
	gen pid = XX8PLPTY
	recode pid (8/9=.)
	
recode pid (1=0) (2=1) (3/7=0), gen(DPJ)
	label var DPJ "Does R support DPJ?"
	label values DPJ ny
	
recode pid (1/3=0) (4/5=1) (6/7=0), gen(leftist)
	label var leftist "Does R support leftist parties?"
	label values leftist ny
	
recode pid (1=1) (2/7=0), gen(LDP)
	label var LDP "Does R support LDP?"
	label values LDP ny
	
***********************************************************************	
*	Economic Ideology	
***********************************************************************
	
*	Redistribution
rename Q5GVEQAA redistribution
	recode redistribution (9=.) (1=5) (2=4) (3=3) (4=2) (5=1)
	label var redistribution "Agree with Government Redistribution"
	label define agree 1 "Strongly Disagree" 2 "Somewhat Disagree" ///
	3 "Neither agree nor Disagree" 4 "Somewhat Agree" 5 "Agree"
	label values redistribution agree
			
*	Nationalism	
***********************************************************************	
rename 	OPNTLINT realism
	label var realism "Should follow national interest even if it leads to conflicts with other nations"
	recode realism (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1) (8/9=.)
	label define agree7 1 "Strongly Disagree" 2 "Disagree" 3 "Somewhat Disagree" ///
	4 "Neither Agree nor Disagree" 5 "Somewhat Agree" 6 "Agree" 7 "Strongly Agree"
	label values realism agree7
	
*	Localism
***********************************************************************
rename EMCLTWN localism
	label var localism "Emotional closeness to town or city of residence"
	recode localism (8/9=.) (1=4) (2=3) (3=2) (4=1)
	label define howclose 1 "Not at all close" 2 "Not so close" 3 "Somewhat close" ///
	4 "Very close"
	label values localism howclose
	
***********************************************************************
*	Economic Background:
***********************************************************************

*	Relative Household income at age 15
rename OPFFIX15 class_origins
	label var class_origins "Comparison of Household Income with Others at Age 15"
	recode class_origins (9=.)
		
***********************************************************************
*	Attitudes on Globalization
***********************************************************************

*	TRADE (Import Restrictions)
gen trade = OPFRNPRD 
	label var trade "Japan should limit imports"
	recode trade (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1) (8/9=.)
	label values trade agree7
	
*	Globalization good for Japanese workers
*rename OPGLBWRK glob_workers
	gen glob_workers = OPGLBWRK
	label var glob_workers "Globalization good for Japanese workers"
	recode glob_workers (1=7) (2=6) (3=5) (4=4) (5=3) (6=2) (7=1) (8/99=.)
	label values glob_workers agree7

*	Acceptance of Foreign Co-Workers
***********************************************************************

*	China
rename ACPFWCN xeno_coworkers_cn
	recode xeno_coworkers_cn (1=1) (2=0) (8/9=.)
	label values xeno_coworkers_cn ny

*	Korea
rename ACPFWSK xeno_coworkers_kr
	recode xeno_coworkers_kr (1=1) (2=0) (8/9=.)
	label values xeno_coworkers_kr ny

*	Taiwan
rename ACPFWTW	xeno_coworkers_tw
	recode xeno_coworkers_tw (1=1) (2=0) (8/9=.)
	label values xeno_coworkers_tw ny

*	Southeast Asia
rename ACPFWSA xeno_coworkers_sa
	recode xeno_coworkers_sa (1=1) (2=0) (8/9=.)
	label values xeno_coworkers_sa ny

*	European Union
rename ACPFWEP xeno_coworkers_eu
	recode xeno_coworkers_eu (1=1) (2=0) (8/9=.)
	label values xeno_coworkers_eu ny
	
*	North America
rename ACPFWNA xeno_coworkers_na
	recode xeno_coworkers_na (1=1) (2=0) (8/9=.)
	label values xeno_coworkers_na ny
	
*	Overall Acceptance of Foreign Co-Workers
recode xeno_coworkers_kr (0/1=1) (.=0), gen(xeno_kr_coworkers_nonmiss)
recode xeno_coworkers_tw (0/1=1) (.=0), gen(xeno_tw_coworkers_nonmiss)
recode xeno_coworkers_cn (0/1=1) (.=0), gen(xeno_cn_coworkers_nonmiss)
recode xeno_coworkers_sa (0/1=1) (.=0), gen(xeno_sa_coworkers_nonmiss)
recode xeno_coworkers_eu (0/1=1) (.=0), gen(xeno_eu_coworkers_nonmiss)
recode xeno_coworkers_na (0/1=1) (.=0), gen(xeno_na_coworkers_nonmiss)

*	Total up non-missing (don't need to use egen b/c none of these should be missing)	
gen xeno_coworkers_nonmiss = xeno_kr_coworkers_nonmiss ///
	+xeno_tw_coworkers_nonmiss+xeno_cn_coworkers_nonmiss+xeno_sa_coworkers_nonmiss ///
	+xeno_eu_coworkers_nonmiss+xeno_na_coworkers_nonmiss

*	Total xeno_coworkers
*NB: have to do it this way b/c if just added together, cannot add if one variable value is missing
egen xeno_coworkers_tot=rowtotal(xeno_coworkers_kr - xeno_coworkers_na)
	
*	Average xeno_coworkers
gen xeno_coworkers_avg = xeno_coworkers_tot / xeno_coworkers_nonmiss


*	Acceptance of Foreign Neighbors
***********************************************************************

*	China
rename ACPFNBCN	xeno_neighbors_cn
	recode xeno_neighbors_cn (1=1) (2=0) (8/9=.)
	label values xeno_neighbors_cn ny

*	Korea
rename ACPFNBSK xeno_neighbors_kr
	recode xeno_neighbors_kr (1=1) (2=0) (8/9=.)
	label values xeno_neighbors_kr ny

*	Taiwan
rename ACPFNBTW xeno_neighbors_tw
	recode xeno_neighbors_tw (1=1) (2=0) (8/9=.)
	label values xeno_neighbors_tw ny

*	Southeast Asia
rename ACPFNBSA xeno_neighbors_sa
	recode xeno_neighbors_sa (1=1) (2=0) (8/9=.)
	label values xeno_neighbors_sa ny

*	European Union
rename ACPFNBEP xeno_neighbors_eu
	recode xeno_neighbors_eu (1=1) (2=0) (8/9=.)
	label values xeno_neighbors_eu ny

*	North America	
rename ACPFNBNA xeno_neighbors_na
	recode xeno_neighbors_na (1=1) (2=0) (8/9=.)
	label values xeno_neighbors_na ny
	
*	Overall Acceptance of Foreign Neighbors
recode xeno_neighbors_kr (0/1=1) (.=0), gen(xeno_kr_neighbors_nonmiss)
recode xeno_neighbors_tw (0/1=1) (.=0), gen(xeno_tw_neighbors_nonmiss)
recode xeno_neighbors_cn (0/1=1) (.=0), gen(xeno_cn_neighbors_nonmiss)
recode xeno_neighbors_sa (0/1=1) (.=0), gen(xeno_sa_neighbors_nonmiss)
recode xeno_neighbors_eu (0/1=1) (.=0), gen(xeno_eu_neighbors_nonmiss)
recode xeno_neighbors_na (0/1=1) (.=0), gen(xeno_na_neighbors_nonmiss)

*	Total up non-missing (don't need to use egen b/c none of these should be missing)	
gen xeno_neighbors_nonmiss = xeno_kr_neighbors_nonmiss ///
	+xeno_tw_neighbors_nonmiss+xeno_cn_neighbors_nonmiss+xeno_sa_neighbors_nonmiss ///
	+xeno_eu_neighbors_nonmiss+xeno_na_neighbors_nonmiss

*	Total xeno_neighbors
*NB: have to do it this way b/c if just added together, cannot add if one variable value is missing
egen xeno_neighbors_tot=rowtotal(xeno_neighbors_kr - xeno_neighbors_na)
	
*	Average xeno_neighbors
gen xeno_neighbors_avg = xeno_neighbors_tot / xeno_neighbors_nonmiss

	
*	Acceptance of Foreign Relatives by Marriage
***********************************************************************	

*	China
rename ACPFRCN xeno_marriage_cn
	recode xeno_marriage_cn (1=1) (2=0) (8/9=.)
	label values xeno_marriage_cn ny

*	Korea
rename ACPFRSK xeno_marriage_kr
	recode xeno_marriage_kr (1=1) (2=0) (8/9=.)
	label values xeno_marriage_kr ny

*	Taiwan
rename ACPFRTW xeno_marriage_tw
	recode xeno_marriage_tw (1=1) (2=0) (8/9=.)
	label values xeno_marriage_tw ny

*	Southeast Asia
rename ACPFRSA xeno_marriage_sa
	recode xeno_marriage_sa (1=1) (2=0) (8/9=.)
	label values xeno_marriage_sa ny

*	Europe
rename ACPFREP xeno_marriage_eu
	recode xeno_marriage_eu (1=1) (2=0) (8/9=.)
	label values xeno_marriage_eu ny

*	North America	
rename ACPFRNA xeno_marriage_na
	recode xeno_marriage_na (1=1) (2=0) (8/9=.)
	label values xeno_marriage_na ny
	
*	Overall Acceptance of Foreign Marriage
recode xeno_marriage_kr (0/1=1) (.=0), gen(xeno_kr_marriage_nonmiss)
recode xeno_marriage_tw (0/1=1) (.=0), gen(xeno_tw_marriage_nonmiss)
recode xeno_marriage_cn (0/1=1) (.=0), gen(xeno_cn_marriage_nonmiss)
recode xeno_marriage_sa (0/1=1) (.=0), gen(xeno_sa_marriage_nonmiss)
recode xeno_marriage_eu (0/1=1) (.=0), gen(xeno_eu_marriage_nonmiss)
recode xeno_marriage_na (0/1=1) (.=0), gen(xeno_na_marriage_nonmiss)

*	Total up non-missing (don't need to use egen b/c none of these should be missing)	
gen xeno_marriage_nonmiss = xeno_kr_marriage_nonmiss ///
	+xeno_tw_marriage_nonmiss+xeno_cn_marriage_nonmiss+xeno_sa_marriage_nonmiss ///
	+xeno_eu_marriage_nonmiss+xeno_na_marriage_nonmiss

*	Total xeno_marriage
*NB: have to do it this way b/c if just added together, cannot add if one variable value is missing
egen xeno_marriage_tot=rowtotal(xeno_marriage_kr - xeno_marriage_na)
	
*	Average xeno_marriage
gen xeno_marriage_avg = xeno_marriage_tot / xeno_marriage_nonmiss


*	Overall "cosmopolitanism" attitude measure
********************************************************************************
*	NB: coded as "cosmopolitanism" because higher numbers are more cosmo
gen cosmo_avg = (xeno_coworkers_avg + xeno_neighbors_avg + xeno_marriage_avg)/3

***********************************************************************
***********************************************************************	
		
*	Merge with TFP Data

***********************************************************************
***********************************************************************

*	Use sdecode command to turn numeric prefecture variable
     sdecode prefecture, gen(pref_name)

saveold "JGSS 2008.dta", replace

import delimited ///
"tfp by prefecture.csv", clear 

***********************************************************************

merge m:m pref_name using ///
"JGSS 2008.dta"

drop _merge

saveold "JGSS 2008.dta", replace

***********************************************************************

*	Recode industry to merge with industry-prefecture tfp
recode industry (10/30=1) (40=2) (50=16) (70=17) (80=21) (91/92=18) ///
		(93=22) (100=19) (110=20) (120=21) (130=21) (140/170=22) (180=23) ///
		(190=.) (60=.), gen(ind_code)
	*	recode ind_code from occupation variable
replace ind_code = 8 if occupation==621 | occupation==623
replace ind_code = 9 if occupation==627 | occupation==628 | occupation==631
replace ind_code = 6 if occupation==629
replace ind_code = 10 if occupation==630
replace ind_code = 11 if occupation==633
replace ind_code = 12 if occupation==634
replace ind_code = 13 if occupation==636 | occupation==638 | occupation==640
*	NB: Coding watch assemblers/repairers as precision machinery
replace ind_code = 14 if occupation==641 | occupation==642
replace ind_code = 3 if occupation==644 | occupation==645
replace ind_code = 15 if occupation==646
replace ind_code = 3 if occupation==647
replace ind_code = 4 if occupation==648 | occupation==649 | occupation==650
replace ind_code = 4 if occupation==651 | occupation==652
replace ind_code = 5 if occupation==657
replace ind_code = 15 if occupation==656 | occupation==659 | occupation==660
replace ind_code = 15 if occupation==668 | occupation==669
replace ind_code = 15 if occupation==681
replace ind_code = . if occupation==704

saveold "JGSS 2008.dta", replace

import delimited ///
"RTFPir.csv", clear 

merge m:m pref_name ind_code using ///
"JGSS 2008.dta"

drop if _merge==1

drop _merge

*	Recode industry to generate manufacturing and service sector indicators
recode industry (10 20 30 40 = 1) ///
 (50 70 80 91 92 93 100 110 120 130 140 150 160 170 = 2) (60=3) (180 = 4) (190 = .), ///
 gen(aggregates)
 
label define aggregates 1 "Primary" 2 "Services" 3 "Manufacturing" 4 "Government"
label values aggregates aggregates

gen manu_serv = .
	replace manu_serv = 1 if aggregates==3
	replace manu_serv = 2 if aggregates==2

***********************************************************************
*	Total up emp_glob employees by prefecture
***********************************************************************

*	mean trade opinion by prefecture
bysort prefecture: egen mean_trade = mean(trade)

*	Total employees of globalized firms by prefecture
bysort prefecture: egen total_emp_glob = sum(emp_glob)

*	Total employees of all kinds by prefecture
bysort prefecture: egen total_emp = sum(employed)

*	Proportion of total employees employed by global firms
gen emp_glob_pct = total_emp_glob / total_emp

***********************************************************************

saveold "JGSS 2008.dta", replace

***********************************************************************
*	Merge Dorn Offshorability Data with JGSS Data:
***********************************************************************
use "DD_occ_isco88.dta", clear

drop if isco88==.

*	pointless to keep observations if task characteristics are missing
drop if occ1990dd==. 

*	ISCO-88 codes are less specific than Dorn's occupation codes
*	Need to consolidate to isco-88 codes to merge with JGSS
bysort isco88: egen mean_task_offshorability = mean(task_offshorability)
bysort isco88: egen mean_task_abstract = mean(task_abstract)
bysort isco88: egen mean_task_routine = mean(task_routine)
bysort isco88: egen mean_task_manual = mean(task_manual)

*	Eliminate duplicates
bysort isco88: gen count = _n
	drop if count!=1
	
drop task_offshorability task_abstract task_routine task_manual

rename mean_task_offshorability task_offshorability
rename mean_task_abstract task_abstract
rename mean_task_routine task_routine
rename mean_task_manual task_manual

/*	
NB: task_manual has 13 observations that = 0
Thus, we should add an arbitrarily small number to these values so that we can 
take the natural log.

*/

replace task_manual = 0.0000000001 if task_manual==0

gen RTI = ln(task_routine) - ln(task_abstract) - ln(task_manual)

merge m:m isco88 using "JGSS 2008.dta"

*	drop unmatched observations from dorn data
drop if _merge==1

drop _merge

saveold "JGSS 2008.dta", replace
saveold "JGSS 2008_int.dta", version(12) replace	
***********************************************************************
*	Merge Blinder Offshorability Data with JGSS Data:
***********************************************************************
merge m:m isco88 using "blindersoc_isco88.dta"

*	drop unmatched observations from Blinder data
drop if _merge==2

drop _merge

saveold "JGSS 2008_Blinder.dta", replace

***********************************************************************
*	Merge Acemoglu and Autor Routineness Data with JGSS Data:
***********************************************************************
use "JGSS 2008.dta", clear

merge m:m isco88 using "Acemoglu_Autor_2011.dta"

*	drop unmatched observations from Acemoglu and Autor data
drop if _merge==2

drop _merge

saveold "JGSS 2008_AA_2011.dta", replace
